Skip to main content
ICT
Lesson A13 - Exceptions and File I/O
 
Main Previous
Title Page >  
Summary >  
Lesson A1 >  
Lesson A2 >  
Lesson A3 >  
Lesson A4 >  
Lesson A5 >  
Lesson A6 >  
Lesson A7 >  
Lesson A8 >  
Lesson A9 >  
Lesson A10 >  
Lesson A11 >  
Lesson A12 >  
Lesson A13 >  
Lesson A14 >  
Lesson A15 >  
Lesson A16 >  
Lesson A17 >  
Lesson A18 >  
Lesson A19 >  
Lesson A20 >  
Lesson A21 >  
Lesson A22 >  
Lesson AB23 >  
Lesson AB24 >  
Lesson AB25 >  
Lesson AB26 >  
Lesson AB27 >  
Lesson AB28 >  
Lesson AB29 >  
Lesson AB30 >  
Lesson AB31 >  
Lesson AB32 >  
Lesson AB33 >  
Vocabulary >  
 

LAB ASSIGNMENT A13.3 page 12 of 12

Squeeze

Assignment:

  1. Students will be provided with a text file, squeeze.txt, containing lines of text, which may or may not have spaces in front of the lines. You will write a class which reads in the lines of text, counts the number of spaces at the beginning of each line, and will write the lines to remove the blanks at the beginning of each line and replace them with an integer count of the number of blanks present.

  2. The number of lines in the file is unknown.

  3. Here is an example of how the data could be changed:

Before squeezing:

// A short example file

private double singleTax (){
    if (income <= 27050.0)
        return (income * 0.15);
    else if (income <= 65550.0)
        return (4057.5 + (0.275 * (income - 27050.0)));
    else if (income <= 136750.0)
        return (14645.0 + (0.305 * (income - 65550.0)));
    else if (income <= 297350.0)
        return (36361.0 + (0.355 * (income - 136750.0)));
    else
        return (93374.0 + (0.391 * (income - 297350.0)));
}

After squeezing:

0  // A short example file
0
0  private double singleTax (){
4  if (income <= 27050.0)
8  return (income * 0.15);
4  else if (income <= 65550.0)
8  return (4057.5 + (0.275 * (income - 27050.0)));
4  else if (income <= 136750.0)
8  return (14645.0 + (0.305 * (income - 65550.0)));
4  else if (income <= 297350.0)
8  return (36361.0 + (0.355 * (income - 136750.0)));
4  else
8  return (93374.0 + (0.391 * (income - 297350.0)));
0 }


Main Previous
Contact
 © ICT 2006, All Rights Reserved.